package com.chat.controller;

import com.chat.service.MessageService;
import com.chat.util.Result;
import com.chat.util.SecurityHolderUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 消息控制器
 *
 * @author wb
 * @since 2025-06-06
 */

@RequestMapping("/message")
@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;


    @GetMapping("/{chatId}")
    public Result<?> getMessageByChatId(@PathVariable("chatId") String chatId) {
        return Result.ok(messageService.getMessagesByChatId(chatId));
    }

    @PostMapping("/markAsRead/{chatId}")
    public Result<?> markMarkAsRead(@PathVariable("chatId") String chatId, HttpSession session) {
        return Result.ok(messageService.updateReadStatus(chatId, SecurityHolderUtil.getUserId(session)));
    }

}
